import type { ResponseData } from '@/utils/types.d';
import { SUCCESS_CODE } from '@/utils/types.d';
import request from '@/utils/request';
import type { DailyDataType, LotInfo, RealTimeParkingRecord } from './types.d';

export async function getDailyStatistic(): Promise<{
  success: boolean;
  message: string;
  data: DailyDataType;
}> {
  const res: ResponseData<DailyDataType> = await request(`/api/statistics/v1.0.0/dashboard/daliy`);
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res?.data };
}

export async function getRealTimeParkingRecord(): Promise<{
  success: boolean;
  message: string;
  data: RealTimeParkingRecord[];
}> {
  const res: ResponseData<RealTimeParkingRecord[]> = await request(
    `/api/statistics/v1.0.0/realtime-msg`,
  );
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res?.data };
}

export async function dashInit(ownerId: string): Promise<{
  success: boolean;
  message: string;
  data: {
    dailyData: DailyDataType;
    msgData: RealTimeParkingRecord[];
  };
}> {
  const res: ResponseData<{
    dailyData: DailyDataType;
    msgData: RealTimeParkingRecord[];
  }> = await request(`/api/statistics/v1.0.0/dashboard/init`, {
    params: { ownerId },
  });
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res?.data };
}

export async function getLotLocation(ownerId: string) {
  const res: ResponseData<LotInfo[]> = await request(`/api/statistics/v1.0.0/dashboard/lotInfo`, {
    params: { ownerId },
  });
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res?.data };
}
